﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MyImage.aspx.cs" Inherits="WebApplicationRating.MyImage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Label ID="lblException" runat="server" Text=" " style="margin-left: 30px" Font-Bold="true" foreColor="Orange" ></asp:Label>
  <p> </p>
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="imageid" DataSourceID="SqlDataSource1"
        EmptyDataText="There are no data records to display." 
        style="margin-right: 0px" CellPadding="10" HorizontalAlign="Center"
        OnRowDeleted ="ImageGridView_RowDeleted"
        OnRowDeleting = "ImageGridView_RowDeleting">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
        <asp:BoundField DataField="imageid" HeaderText="ImgId" 
            SortExpression="imageid" InsertVisible="False" ReadOnly="True" />
        <asp:BoundField DataField="name" HeaderText="Name" 
            SortExpression="name" />
<asp:TemplateField HeaderText="Image">
 <ItemTemplate>
   <asp:Image ID="Image1" runat="server" ImageUrl='<%# "Handler.ashx?imageid=" + Eval("imageid")%>' Width = "150" />
  </ItemTemplate>
</asp:TemplateField>
        <asp:BoundField DataField="categoryid" HeaderText="CatId" 
            SortExpression="categoryid" ReadOnly="True" />
        <asp:BoundField DataField="category_name" HeaderText="Category" 
            SortExpression="category_name" ReadOnly="True" />
        <asp:BoundField DataField="AvgRatingAvailable" HeaderText="AvgRating" 
            SortExpression="AvgRatingAvailable" 
            ReadOnly="True" DataFormatString="{0:n2}" />
        <asp:BoundField DataField="loadDate" HeaderText="loadDate" 
            SortExpression="loadDate" ReadOnly="True" />
        <asp:BoundField DataField="user_upload_comment" Visible="false" 
            ReadOnly="True"/>
   <asp:TemplateField HeaderText="Comment"> 
    <ItemTemplate>
         <div style="overflow:auto; height: 150px; width: 80px; ">
         <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("user_upload_comment")%>' /> 
        </div>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:imageConnectionString2 %>"
    InsertCommand="INSERT INTO [UserImageRating] ([userid], [imageid], [rating], [rating_date]) VALUES (@userid, @imageid, @rating, @rating_date)" 
    ProviderName="<%$ ConnectionStrings:imageConnectionString2.ProviderName %>" 
    SelectCommand="SELECT imageid, name, categoryid, category_name, user_upload_comment, CONVERT (varchar, upload_date, 103) AS loadDate, AvgRatingAvailable, Image FROM (SELECT TOP (100) PERCENT Image.imageid, derivedtbl_1.categoryid, derivedtbl_1.category_name, Image.name, Image.user_upload_comment, Image.upload_date, derivedtbl_1.Expr1 AS AvgRatingAvailable, Image.image_file AS Image FROM (SELECT UserImage.imageid, ImageCategory.categoryid, Category.category_name, AVG(UserImageRating.rating) AS Expr1 FROM UserImageRating RIGHT OUTER JOIN UserImage ON UserImageRating.imageid = UserImage.imageid INNER JOIN ImageCategory ON UserImage.imageid = ImageCategory.imageid INNER JOIN Category ON ImageCategory.categoryid = Category.categoryid WHERE (UserImage.userid = @curUSR) AND (ISNULL(UserImageRating.userid, 0) &lt;&gt; @curUSR) GROUP BY UserImage.imageid, ImageCategory.categoryid, Category.category_name) AS derivedtbl_1 INNER JOIN Image ON derivedtbl_1.imageid = Image.imageid) AS derivedtbl_2 ORDER BY loadDate DESC" 
    OnSelecting="SqlDataSource_Selecting"       
    
        
        
        
        
        UpdateCommand="UPDATE Image SET name = @name WHERE (imageid = @imageid)" 
        
        DeleteCommand="DELETE FROM Image WHERE (imageid = @imageid) AND (0 IN (SELECT COUNT(*) AS Expr1 FROM ImageCategory WHERE (imageid = @imageid)))">
    <DeleteParameters>
        <asp:Parameter Name="imageid" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="userid" Type="Int32" />
        <asp:Parameter Name="imageid" Type="Int32" />
        <asp:Parameter Name="rating" Type="Int32" />
        <asp:Parameter Name="rating_date" Type="DateTime" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="name" />
        <asp:Parameter Name="imageid" Type="Int32" />
    </UpdateParameters>
    <SelectParameters> 
        <asp:Parameter Name="curUSR" Type="Int32" /> 
    </SelectParameters> 
</asp:SqlDataSource>
</asp:Content>
